<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>编辑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/web/res/css/xadmin.css">
    <script src="/web/res/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/web/res/js/xadmin.js"></script>
</head>

<body style="background-color: white;">
<div class="layui-fluid" id="orderEdit">
    <form class="layui-form layui-form-pane" id="formsubmit" style="width: 500px;margin:20px auto"
          action="/after/spouse/addOrEditDo">
        <input type="hidden" name="id" value="${(info.id?c)!''}"/>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 124px">脸型</label>
            <div class="layui-input-block" style="margin-left: 124px">
                <input type="text" name="faceType" required lay-verify="required" autocomplete="off"
                       class="layui-input"
                       value="${(info.faceType)!''}"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 124px">招人爱指数</label>
            <div class="layui-input-block" style="margin-left: 124px">
                <input type="text" name="loveIndex" required lay-verify="required" autocomplete="off"
                       class="layui-input"
                       value="${(info.loveIndex)!''}"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 124px">招人爱属性1</label>
            <div class="layui-input-block" style="margin-left: 124px">
                <input type="text" name="loveAttribute1" required lay-verify="required" autocomplete="off"
                       class="layui-input"
                       value="${(info.loveAttribute1)!''}"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 124px">招人爱属性1占比(%)</label>
            <div class="layui-input-block" style="margin-left: 124px">
                <input type="number" name="loveAttributeIndex1" required lay-verify="required" autocomplete="off"
                       class="layui-input"
                       value="${(info.loveAttributeIndex1?c)!''}"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 124px">招人爱属性2</label>
            <div class="layui-input-block" style="margin-left: 124px">
                <input type="text" name="loveAttribute2" required lay-verify="required" autocomplete="off"
                       class="layui-input"
                       value="${(info.loveAttribute2)!''}"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 124px">招人爱属性2占比(%)</label>
            <div class="layui-input-block" style="margin-left: 124px">
                <input type="number" name="loveAttributeIndex2" required lay-verify="required" autocomplete="off"
                       class="layui-input"
                       value="${(info.loveAttributeIndex2?c)!''}"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 124px">招人爱属性3</label>
            <div class="layui-input-block" style="margin-left: 124px">
                <input type="text" name="loveAttribute3" required lay-verify="required" autocomplete="off"
                       class="layui-input"
                       value="${(info.loveAttribute3)!''}"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 124px">招人爱属性3占比(%)</label>
            <div class="layui-input-block" style="margin-left: 124px">
                <input type="number" name="loveAttributeIndex3" required lay-verify="required" autocomplete="off"
                       class="layui-input"
                       value="${(info.loveAttributeIndex3?c)!''}"/>
            </div>
        </div>
<!--        <div class="layui-form-item">-->
<!--            <div class="layui-upload">-->
<!--                <label class="layui-form-label lable-text-center">家族头像</label>-->
<!--                <div class="upload-list" id="uploadlist">-->
<!--                    <#if info?exists && info.pic?exists && info.pic?length gt 2>-->
<!--                    <div class="upload-imgBox">-->
<!--                        <input type="hidden" id="imgpathhide" value="${(info.pic)!''}" class="layui-input"/>-->
<!--                        <div class="upload-cancel">x</div>-->
<!--                        <img src="${(info.pic)!''}" class="upload-select-img">-->
<!--                    </div>-->
<!--                    <div class="upload-img" id="uploadtemplate" style="display:none;">+</div>-->
<!--                    <#else>-->
<!--                    <div class="upload-img" id="uploadtemplate">+</div>-->
<!--                </#if>-->
<!--            </div>-->
<!--        </div>-->
<!--</div>-->
<div class="layui-form-item ">
    <label class="layui-form-label" style="width: 124px">脱单特性</label>
    <div class="layui-input-block" style="margin-left: 124px">
        <input type="text" name="deOrderType" required lay-verify="required" autocomplete="off" class="layui-input" value="${(info.deOrderType)!''}"/>
    </div>
</div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 124px">特长</label>
            <div class="layui-input-block" style="margin-left: 124px">
                <input type="text" name="specialty" required lay-verify="required" autocomplete="off" class="layui-input" value="${(info.specialty)!''}"/>
            </div>
        </div>
        <div class="layui-form-item ">
            <label class="layui-form-label" style="width: 124px">DNA类型</label>
            <div class="layui-input-block" style="margin-left: 124px">
                <input type="text" name="dnaType" required lay-verify="required" autocomplete="off" class="layui-input" value="${(info.dnaType)!''}"/>
            </div>
        </div>
        <div class="layui-form-item ">
            <label class="layui-form-label" style="width: 124px">恋爱中的形象</label>
            <div class="layui-input-block" style="margin-left: 124px">
                <input type="text" name="loveImage" required lay-verify="required" autocomplete="off" class="layui-input" value="${(info.loveImage)!''}"/>
            </div>
        </div>

        <div class="layui-form-item ">
            <label class="layui-form-label" style="width: 124px">综合分析</label>
            <div class="layui-input-block" style="margin-left: 124px">
                <input type="text" name="allAnalysis" required lay-verify="required" autocomplete="off" class="layui-input" value="${(info.allAnalysis)!''}"/>
            </div>
        </div>
        <div class="layui-form-item ">
            <label class="layui-form-label" style="width: 124px">性别</label>
            <div class="layui-input-block" style="margin-left: 124px">
                <select name="sex" lay-filter="jiangpinType">
                    <option value="1" <#if info?exists && info.sex?exists && (info.sex)?number ==1>selected</#if>>男</option>
                <option value="2" <#if info?exists && info.sex?exists && (info.sex)?number ==2>selected</#if>>女</option>
            </select>
        </div>

<div class="layui-form-item ">
    <label class="layui-form-label" style="width: 124px">状态</label>
    <div class="layui-input-block" style="margin-left: 124px">
        <select name="status" lay-filter="jiangpinType">
            <option value="1" <#if info?exists && info.status?exists && (info.status)?number ==1>selected</#if>>可用</option>
        <option value="2" <#if info?exists && info.status?exists && (info.status)?number ==2>selected</#if>>禁用</option>
    </select>
</div>
</div>
<div class="layui-form-item">
    <div class="layui-input-block">
        <button type="button" class="layui-btn layui-btn-radius" lay-submit lay-filter="save">&emsp;保存&emsp;
        </button>
        <button type="button" class="layui-btn layui-btn-primary layui-btn-radius" onclick="xadmin.close()">
            &emsp;返回&emsp;
        </button>
    </div>
</div>
</form>
</div>
<script>
    layui.use(['form', 'upload'], function () {
        let $ = layui.$;
        var form = layui.form;
        var upload = layui.upload;
        form.render();
        // 重新添加删除功能
        $('.upload-cancel').on('click', (event) => {
            let self = $(event.currentTarget);
            self.parent().remove();
            event.stopPropagation();

            if ($("input[id='imgpathhide']").length < 1) {
                $('#uploadtemplate').show();
            } else {
                $('#uploadtemplate').hide();
            }
        });
        upload.render({
            elem: '#uploadtemplate',
            // auto: false,
            url: '/after/family/uppic',
            accept: 'images',
            acceptMime: 'image/*',
            choose: function (obj) {
            },
            done: function (res) {
                console.log(res)
                $('#uploadlist').prepend(
                    '<div class="upload-imgBox">  <input type="hidden"  id="imgpathhide" value="' + res.data + '"  class="layui-input"/><div class="upload-cancel">x</div><img  src="' + res.data + '" class="upload-select-img"></div>');
                $(".upload-cancel").on("click", function (e) {
                    $(this).parent().remove();
                    if ($("input[id='imgpathhide']").length < 1) {
                        $('#uploadtemplate').show();
                    }
                })
                if ($("input[id='imgpathhide']").length >= 1) {
                    $('#uploadtemplate').hide();
                }
            }
        });

        // upload.render({
        //     elem: '#uploadtemplate',
        //     auto: false,
        //     accept: 'images',
        //     acceptMime: 'image/*',
        //     choose: function (obj) {
        //         obj.preview(function (index, file, result) {
        //             $('#uploadlist').prepend('<div class="upload-imgBox">  <input type="hidden"  id="imgpathhide" value="' + result + '"  class="layui-input"/><div class="upload-cancel" id="' + index + '">x</div><img  src="' + result + '" alt="' + file.name +
        //                     '" class="upload-select-img"></div>');
        //             $(".upload-cancel").on("click", function (e) {
        //                 $(this).parent().remove();
        //                 if ($("input[id='imgpathhide']").length < 1) {
        //                     $('#uploadtemplate').show();
        //                 }
        //             })
        //             if ($("input[id='imgpathhide']").length >= 1) {
        //                 $('#uploadtemplate').hide();
        //             }
        //             // alert($("input[id='imgpathhide']").length);
        //         });
        //     },
        //     done: function (res) {

        //     }
        // });

        $.fn.extend({
            serializeObject: function () {
                var obj = {}; //声明一个对象
                $.each(this.serializeArray(), function (index, field) {
                    obj[field.name] = field.value; //通过变量，将属性值，属性一起放到对象中
                })
                return obj;
            }
        });
        form.on('submit(' + $("button[lay-submit]:eq(0)").attr("lay-filter") + ')', function (data) {

            // $("input[id='imgpathhide']").each(function (index, ele) {
            //     $(this).attr("name", "pic");
            // });
            layer.confirm('确认要保存吗？', function (index) {

                var loading = layer.load(0, {
                    shade: true
                });
                ajaxPost($, $("#formsubmit").attr("action"), $("#formsubmit").serializeObject(), function (data) {
                    layer.close(loading);
                    if (data.code == 0) {

                        layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                            xadmin.father_reload();
                        });
                    } else {
                        layer.close(loading);
                        layer.msg(data.msg, {icon: 2, time: 3000}, function () {

                        });
                    }
                });
            });
        });
    });
</script>
</body>

</html>